if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

set nocompatible	" Use Vim defaults (much better!)
set bs=indent,eol,start		" allow backspacing over everything in insert mode
"set ai			" always set autoindenting on
"set backup		" keep a backup file
set viminfo='20,\"50	" read/write a .viminfo file, don't store more
			" than 50 lines of registers
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time


"=========== added by Jacob.Ho==========

syntax enable
syntax on
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4		
set expandtab
"set guifont=Courier\ 10
set guifont=Monospace\ 9
"set for tool bar disappeared
set guioptions-=T
" set for fold
set foldmethod=syntax
filetype on
filetype plugin on
filetype indent on

" set for save changes
nmap ww :w!<CR>

"set for Make
nmap mk :make<CR>

" set for vimgdb
"nmap <F9> :run macros/gdb_mappings.vim<CR>

" set for ctags
set tags=/usr/include/tags
"set tags+=/lib/modules/2.6.28-11-generic/build/include/tags
"set tags=/media/disk/work/src/s3c6410-2.6.27-samsung/include/tags

" set for Tlist
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
"let Tlist_Use_Right_Window = 1

" set for wmanger
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>

" set for cscope===
" <C-_>g的按法是先按"Ctrl+Shift+-", 然后很快再按"g"
set cscopequickfix=s-,c-,d-,i-,t-,e- 
" 该函数都在何处被调用
nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
" 查找本函数调用到的函数
nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>	

" 查找该符号(含定义类型）
nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
" 查找符号定义
nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找该字符串
nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>	
" 查找本egrep模式
nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
" 查找本文件
nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找包含本文件的文件
nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR><CR>


" set for quickfix 
nmap <F8> :cw<cr>
nmap <F6> :cn<cr>
nmap <F7> :cp<cr>

" set for miniBufExp
let g:miniBufExplMapWindowNavArrows = 1

" set for .a <-> .h
nnoremap <silent> <F12> :A<CR>

" set for grep.vim 对鼠标处字符串在当前目录中搜索
nnoremap <silent> <F3> :Grep<CR>

" lookupfile setting
" 最少输入2个字符才开始查找
let g:LookupFile_MinPatLength = 2
" 不保存上次查找的字符串              
let g:LookupFile_PreserveLastPattern = 0
" 保存查找历史        
let g:LookupFile_PreservePatternHistory = 1
" 回车打开第一个匹配项目     
let g:LookupFile_AlwaysAcceptFirst = 1
"不允许创建不存在的文件          
let g:LookupFile_AllowNewFiles = 0
"设置tag文件的名字              
if filereadable("./filenametags")                
let g:LookupFile_TagExpr = '"./filenametags"'
endif
"映射LookupFile为,lk
"nmap <silent> <leader>lk <Plug>LookupFile<cr>
"映射LUBufs为,ll   
"nmap <silent> <leader>lb :LUBufs<cr>
"映射LUWalk为,lw             
"nmap <silent> <leader>lw :LUWalk<cr>

" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
    let _tags = &tags
    try
        let &tags = eval(g:LookupFile_TagExpr)
        let newpattern = '\c' . a:pattern
        let tags = taglist(newpattern)
    catch
        echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
        return ""
    finally
        let &tags = _tags
    endtry

    " Show the matches for what is typed so far.
    let files = map(tags, 'v:val["filename"]')
    return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'            

" set for Visual Mark
if &bg == "dark" 
 highlight SignColor ctermfg=white ctermbg=blue guifg=wheat guibg=peru
else 
 highlight SignColor ctermbg=white ctermfg=blue guibg=grey guifg=RoyalBlue3
endif


"======== added by Jacob.Ho

" Only do this part when compiled with support for autocommands
if has("autocmd")
  " In text files, always limit the width of text to 78 characters
  autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

if &term=="xterm"
     set t_Co=8
     set t_Sb=[4%dm
     set t_Sf=[3%dm
endif
